import Config from './config';
import SHA1 from './sha1'

const ENV = 'mainnet';
// const ENV = 'testnet';
// const ENV = 'localhost';

let util = {

};

console.log("============================");
console.log("[ENV]" + ENV);
console.log("============================");

util.config = Config(ENV);

util.noWallet = typeof(webExtensionWallet) === "undefined";

util.getAccount = function (self) {
  if(typeof(webExtensionWallet) === "undefined"){
    return;
  }

  window.postMessage({
    "target": "contentscript",
    "data":{},
    "method": "getAccount",
  }, "*");

  window.addEventListener('message', function(e) {
    if(e.data && e.data.data && e.data.data.account){
      const address = e.data.data.account;
      localStorage.setItem('nasAddress', address);
    }
  });
};

var nebulas = require("nebulas")
util.nebulas = nebulas;

// var neb = new nebulas.Neb();
// neb.setRequest(new nebulas.HttpRequest(util.config.reqhost));
// util.neb = neb;

var NebPay = require('nebpay.js');
util.nebPay = new NebPay();

util.sha1 = SHA1;

export default util;
